const { Readable } = require("stream");
const utils = require('../../utils');

module.exports = async function (list) {
  const stream = new Readable({ objectMode: true });
  let rowNo = 0, total = list.length;
  stream._read = async function () {
    if (rowNo < total) {
      stream.push(list[rowNo]);
    } else {
      stream.push(null);
    }
    rowNo++;
  };

  stream.on('end', () => {
    utils.debug('listReader [end]');
  });
  
  return stream;
}